<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button id='button'>创建登录框</button>
  <button id='close'>关闭登录框</button>
  <script>
    const single = function (fn) {
      let result
      return function () {
        return result || (result = fn.apply(this, arguments))
      }
    }

    const createLogin = function () {
      const div = document.createElement('div')
      div.id = 'login'
      div.style.display = 'none'
      div.innerHTML = '我是登录框哦'
      document.body.appendChild(div)
      return div
    }

    const singleCreateLogin = single(createLogin)

    document.getElementById('button').onclick = function () {
      const div = singleCreateLogin()
      div.style.display = 'block'
    }
    document.getElementById('close').onclick = function () {
      document.getElementById('login').style.display = 'none'
    }
  </script>
</body>

</html>
